package com.ow.dva.module.park.service.impl;

import com.ow.dva.module.base.entity.param.DvaPage;
import com.ow.dva.module.base.service.impl.DvaServiceImpl;
import com.ow.dva.module.park.entity.AreaParkinglot;
import com.ow.dva.module.park.entity.Parkinglot;
import com.ow.dva.module.park.mapper.AreaParkinglotMapper;
import com.ow.dva.module.park.mapper.ParkinglotMapper;
import com.ow.dva.module.park.service.AreaParkinglotService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 车位分区关联表 服务实现类
 * </p>
 *
 * @author YanZengBao
 * @since 2020-02-20
 * @version V1.0
 */
@Service
public class AreaParkinglotServiceImpl extends DvaServiceImpl<AreaParkinglotMapper, AreaParkinglot> implements AreaParkinglotService {

    @Resource
    ParkinglotMapper parkinglotMapper;

//    @DvaCache5M
    @Override
    public DvaPage<AreaParkinglot> page(DvaPage<AreaParkinglot> page, Map<String, Object> param) {

        return baseMapper.page(page,param);
    }

    @Override
    public int untying(String areaParkinglotId) {

        AreaParkinglot areaParkinglot = baseMapper.selectById(areaParkinglotId);
        if (areaParkinglot != null){
            Parkinglot parkinglot = parkinglotMapper.selectById(areaParkinglot.getParkinglotId());
            if(parkinglot != null){
                parkinglot.setStatus(0);
                parkinglotMapper.updateById(parkinglot);
            }
        }
        return baseMapper.deleteById(areaParkinglotId);
    }

    @Override
    public int untying(String id, String areaId) {

        Map map = new HashMap();
        map.put("parkinglotId",id);
        map.put("areaId",areaId);
        AreaParkinglot areaParkinglot = baseMapper.selectByParkinglotIdAndAreaId(map);
        if (areaParkinglot != null){
            Parkinglot parkinglot = parkinglotMapper.selectById(areaParkinglot.getParkinglotId());
            if(parkinglot != null){
                parkinglot.setStatus(0);
                parkinglotMapper.updateById(parkinglot);
            }
            return baseMapper.deleteById(areaParkinglot);
        }else{
            return 0;
        }
    }
}
